#ifndef TCPSEVER_H
#define TCPSEVER_H

#include <QObject>
#include <QVector>
#include <QMap>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QTcpServer>
#include <QTcpSocket>
#include <databasemanager.h>
//#include "log.h"

class ServerManager : public QObject {
    Q_OBJECT
public:
    QTcpServer* server=nullptr;
    QList<QTcpSocket*> clients; // 存放连接TcpServer的套接字信息
};


class TCpsever : public QObject
{
    Q_OBJECT
public:
    explicit TCpsever(QObject *parent = nullptr);

    QMap<int, QVector<QVariant>> readDatabase(QSqlDatabase& db); // 读取数据库的信息

    void setupTcpServer(int key,QVector<QVariant> Row);     // 具体服务器的操作

    void sendData(const int& clinetPort, const QByteArray &data);
//    void setLogger(Log *logger);
    void init();
signals:
        void serverDataReceived(int port, const QByteArray& data);
public slots:
        void onserverDataReceived(int index, const QByteArray& data);   // 收到客户端发送的信息触发


private:
    QMap<int, QVector<QVariant>> serviceData;   // 存放读取出的数据库信息
    QMap<int,ServerManager*> servermanager;     // 存放服务器*server，QTcpSocket
//    Log* m_logger;
};

#endif // TCPSEVER_H
